package jpb.hotspot;

import jpb.CommandArg;
import jpb.CoreJvmArgs;
import jpb.MemArg;

/**
 * {@link jpb.JvmArg} implementation for Hotspot supporting the JVM's max memory arg.
 *
 * @see jpb.JvmArg
 * @see jpb.MemArg
 * @see jpb.Jvm#maxMemoryArg()
 * @author Dariusz Kordonski
 */
public class MaxMemoryArg extends CoreJvmArgs.AbstractMaxMemoryArg {

    private static final String ARG_TEMPLATE = "-Xmx%s";

    protected MaxMemoryArg() {
        super(HotspotJvm.class);
    }

    @Override
    protected void validate(MemArg argValue) {
        MemArgUtil.validateMemUnit(argValue.unit(), this);
    }

    @Override
    protected CommandArg convert(MemArg argValue) {
        return CommandArg.of(format(argValue));
    }

    private String format(MemArg argValue) {
        return String.format(ARG_TEMPLATE, MemArgUtil.formatMemArg(argValue));
    }
}
